<?php
class PC4_Controlador_GoogleAnalytics extends Zend_Controller_Action {
	// Informações do Google Analytics
	public $email, $senha, $idPerfil;
	
	function indexAction() {
		
		$email = $this->email;
		$senha = $this->senha;
		$idPerfil = $this->idPerfil;
				
		$ga = new gapi($email, $senha);
		
		$start_date = null;
		$end_date = null;
		$mes = date('m');
		$ano = date('Y');

		if (!empty($_POST['mes'])) {
			$mes = $_POST['mes'];
			$ano = $_POST['ano'];
			$dia = date("t", mktime(0, 0, 0, $mes, 1, $ano));
			$start_date = "$ano-$mes-01";
			$end_date = "$ano-$mes-$dia";
		}
		
		$porPaginas = $ga->requestReportData($idPerfil, array('pagePath'), array(
			'pageviews', 
			'visits'
		), '-pageviews', null, $start_date, $end_date, 1, 100);
		$porDatas = $ga->requestReportData($idPerfil, array('date'), array('visits'), 'date', null, $start_date, $end_date);
		$media = $ga->requestReportData($idPerfil, array('visitLength'), array('timeOnSite'), null, null, $start_date, $end_date);
//		new d($media);die;
		$this->view->porPaginas = $porPaginas;
		$this->view->porDatas = $porDatas;
		$this->view->mes = $mes;
		$this->view->ano = $ano;
		
	}
	
}